<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="language" content="zh-CN">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" type="text/css" href="./css/style.css">
    <script th:src="@{/js/jquery-1.11.2.min.js}"></script>
    <link th:href="@{/css/bootstrap.css}" rel="stylesheet">
    <title>淘宝优惠券</title>
    <style>

        .div-parent {
            width: 100%;
        }

        .div-child {
            margin: 0 auto;
        }

    </style>

</head>
<body>
<div class="new_home">
    <div id="headNav">
        <div id="header">
            <a class="header_logo" href="#"
               style="background: url('images/logo.png') left top no-repeat;">
            </a>


            <div id="showList">
                <div id="search">
                    <input type="hidden" name="h_kw" id="h_kw" value="六一儿童节礼物">
                    <input type="hidden" name="h_url" id="h_url"
                           value="/index.php?r=l">
                    <input type="hidden" name="m_url" id="m_url">
                    <form action=""
                          method="get">
                        <input type="hidden" name="r" value="l"> <input
                            type="text" autocomplete="off"
                            class="theme-border-color-1 my-src-input" th:value="${kw}" name="kw"
                            placeholder="六一儿童节礼物">
                        <button class="theme-bg-color-1 my-src-btn" type="submit">搜 索</button>
                    </form>
                    <div class="rec_word">
                        <a href="#" style="color: red;">沐浴露</a>
                        <a href="#" style="">手表</a>
                        <a href="#" style="">拖鞋</a>
                        <a href="#" style="">连衣裙</a>
                        <a href="#" style="">睡衣</a>
                    </div>
                </div>
            </div>
            <img class="head_group fr" src="./images/headgrup.png" alt="">
        </div>
    </div>

    <div id="baner" class="theme-bg-color-1">
        <div id="nav">
            <a href="#" class="theme-hover-bg-color-8 active "> 首页 </a>
            <a href="#" class="theme-hover-bg-color-8"> 9块9包邮 </a>
            <a href="#" class="theme-hover-bg-color-8">每日半价 <i class="new">New!</i></a>
        </div>
    </div>

    <div id="dtk_mian">
        <div class="year-bg">
            <div class="nine_center w_1200">
                <div class="nine_nav_link ">
                    <div class="center">
                        <a href="#" class="link active "> 精选 </a>
                        <a href="#" class="link"> 居家百货 </a>
                        <a href="#" class="link"> 美食 </a>
                        <a href="#" class="link"> 服装 </a>
                        <a href="#" class="link"> 配饰 </a>
                        <a href="#" class="link"> 美妆 </a>
                        <a href="#" class="link"> 内衣 </a>
                        <a href="#" class="link"> 母婴 </a>
                        <a href="#" class="link"> 箱包 </a>
                        <a href="#" class="link"> 数码配件 </a>
                        <a href="#" class="link"> 文娱车品 </a>
                    </div>
                </div>

                <div class="goods-list main-container new_comp">
                    <ul class="clearfix" id="goodsItems">
                        <!-- 优惠券列表 -->
                    </ul>
                </div>

                <div style="text-align: center">
                    <img id="spin" src="/images/spin.gif" alt="" width="50px" style="display: none">
                </div>
            </div>
        </div>
    </div>


    <div id="footer" class="com-footer" style="height: auto">
        <div class="footer-wrapper">
            <ul>
                <li>网站导航</li>
                <li><a href="#">首页</a></li>
                <li><a href="#">好货精选</a></li>
                <li><a href="#">9.9包邮</a></li>
                <li><a href="#">关于我们</a></li>
                <li><a href="#">广告加盟</a></li>
            </ul>
            <p>妈妈优惠券是一家导购网站，网站中的商品信息均来自于互联网。如商品信息不同，可能是商品信息未及时更新，所有商品信息请以天猫/淘宝店铺内为准。</p>
            <div class="text">
                <span>版权所有 本站内容未经书面许可,禁止一切形式的转载</span>
                © CopyRight&nbsp;2019
            </div>

        </div>
    </div>
</div>


<ul class="float-tool">
    <li onclick="alert('暂未实现')"><img src="./images/sc.png" alt=""> <p>收藏</p></li>
    <li onclick="alert('暂未实现')"><img src="./images/share.png" alt=""> <p>分享</p></li>
    <li onclick="alert('暂未实现')"><img src="./images/kf.png" alt=""> <p>客服</p></li>
    <li onclick="alert('暂未实现')"><img src="./images/feedback.png" alt=""> <p>反馈</p></li>
</ul>

<script>
    $(function(){
        //页面上的全局变量
        var page = 1
        getPage()  //页面加载完成后，立即加载第一页数据

        function getPage() {
            //取消滚动事件
            $(document).off('scroll')

            $.ajax({
                url: './couponAjax',
                type: 'get',
                data: 'pageNum=' + page,
                beforeSend: function (){
                    $('#spin').show()
                },
                success: function (res) {
                    if(res.length == 0){  //没有下一页
                        $('#spin').replaceWith("<p>我也是有底线的~~</p>")
                    }else {
                        $.each(res, function (i, c) {
                            var chtml = '<li class="g_over">\n' +
                                '                                <a href="' + c.couponTbkUrl + '" class="img" target="_blank">\n' +
                                '                                    <img src="' + c.goodPic + '">\n' +
                                '                                </a>\n' +
                                '                                <div class="goods-padding">\n' +
                                '                                    <div class="title">\n' +
                                '                                        <a target="_blank" href="' + c.couponTbkUrl + '">\n' +
                                '                                            <i class="tag tag-tmall fl" title="天猫"></i>\n' +
                                '                                            <span>' + c.goodName + '</span>\n' +
                                '                                        </a>\n' +
                                '                                    </div>\n' +
                                '                                    <div class="goods-num-type">\n' +
                                '                                        <span class="old-price fl">原价 <i>' + c.price + '</i></span>\n' +
                                '                                        <span class="goods-num fr">\n' +
                                '\t\t\t\t\t\t\t\t\t\t\t销量<i>' + c.sales + '</i>\n' +
                                '                                        </span>\n' +
                                '                                    </div>\n' +
                                '                                    <div class="coupon-wrap clearfix">\n' +
                                '\t\t\t\t\t\t\t\t\t\t\t<span class="price"><i>￥</i><span>' + c.promotePrice + '</span>\n' +
                                '\t\t\t\t\t\t\t\t\t\t\t</span><b class="coupon fr"><i>' + c.couponValue + '</i> 元券</b>\n' +
                                '                                    </div>\n' +
                                '                                </div> <em class="border_l_b border"></em> <em\n' +
                                '                                        class="border_l_t border"></em> <em class="border_r_b border"></em>\n' +
                                '                                <em class="border_r_t border"></em>\n' +
                                '                            </li>'

                            $('#goodsItems').append(chtml)
                        })

                        //当前页数加1
                        page++
                        onScroll()  //重新绑定滚动事件
                    }
                },
                complete: function(){
                    $('#spin').hide()
                }
            })
        }

        function onScroll(){
            //注册滚动事件，检查页面是否滚动到了底部
            $(document).scroll(function () {
                // console.log($(document).scrollTop());  //滚动条高度
                // console.log(window.innerHeight);     //窗口高度
                // console.log($(document).height());   //文档高度
                //滚动条高度 + 窗口高度 = 文档高度

                if ($(document).scrollTop() + window.innerHeight >= $(document).height() - 100) {
                    console.log("请求下一页" + page)
                    getPage()
                }

            });
        }
    })
</script>

</body>


</html>